package T58;

import com.SemaphoreTest;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

public class one {
    public static void main(String[] args) {
        ThreadLocal<Thread> t  = new ThreadLocal<>();
        ArrayList<String> arrayList = new ArrayList<>();
        arrayList.add("0");
        one o = new one();
        System.out.println(o.w(12158));
        System.out.println(arrayList.get(0));
    }
    public ArrayList<String> findCommonString (ArrayList<ArrayList<String>> values) {
        Set<String> set = new HashSet<>();
        ArrayList<String> arrayList = new ArrayList<>();
        for (int i = 0; i <values.get(0).size() ; i++) {
            set.add(values.get(0).get(i));
        }
        for (int i = 1; i <values.size() ; i++) {
            for (int j = 0; j <values.get(i).size() ; j++) {
                int temp = set.size();
                set.add(values.get(i).get(j));
                if(temp!=set.size()){
                    arrayList.add(values.get(i).get(j));
                }
            }
        }
        return arrayList;
    }

    public int question (int a, int b) {
        // write code here
        for (int i = 0; i < 500; i++) {
            int temp = (int)Math.sqrt(a+i);
            if(Math.pow(temp,2)==a+i){
                int tempb = (int)Math.sqrt(b+i);
                if(Math.pow(tempb,2)==b+i){
                    return i;
                }
            }
        }
        return 0;
    }

    public int translateNum (int num) {
        // write code here
        String str = String.valueOf(num);
        int a = str.length();
        int tempa = 1;
        int c = 2;
        int count = 0;
        for (int i = 0; i < a; i++) {
            count+=c + tempa;
            c = count;
            tempa = c;
        }
        for (int i = 0; i < str.length()-1; i++) {
            int temp = str.charAt(i);
            int t = temp*10 + str.charAt(i+1);
            if(t>25){
                count--;
            }

        }
        return count;
    }
    public int w (int num) {
        String str = String.valueOf(num);
        int length = str.length();
        if(length==1){
            return 1;
        }
        int a=1,b=1,c=1;
        if(can(str.charAt(0), str.charAt(1))){
            b = 2;
        }
        a=b;
        for (int i = 2; i < length; i++) {
            a = b;
            if(can(str.charAt(i-1), str.charAt(i))){
                a += c;
            }
            c = b;
            b = a;
        }
        return a;
    }
    public boolean can(int a,int b){
        if(a>2||a==2&&b>5||a==0){
            return false;
        }
        return true;
    }
}
